package com.moefor.clover.init;

import java.util.EnumSet;

import javax.servlet.DispatcherType;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;

import org.springframework.core.annotation.*;
import org.springframework.orm.hibernate5.support.OpenSessionInViewFilter;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.filter.DelegatingFilterProxy;
import org.springframework.web.servlet.DispatcherServlet;

import com.moefor.clover.init.config.AppConfig;
import com.moefor.clover.init.config.DispatcherServletConfig;

@Order(1)
public class CommonInitializer implements WebApplicationInitializer{
	
	public void onStartup(ServletContext servletContext) throws ServletException {
		//OpenSessionInViewFilter 配置
		OpenSessionInViewFilter openSessionInViewFilter = new OpenSessionInViewFilter();
		javax.servlet.FilterRegistration.Dynamic openSessionInViewFilterDynamic =  servletContext.addFilter("OpenSessionInView", openSessionInViewFilter);
		openSessionInViewFilterDynamic.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.ERROR), false, "/*");
		
		//log4j2 配置
		System.setProperty("log4j.configurationFile", "/config/log4j2.properties");
	}
}
